package com.czy.tank.game;

import com.czy.tank.common.Group;
import com.czy.tank.config.ResourceMgr;

import java.awt.Graphics;

public class Explode {
	public static int WIDTH ;
	public static int HEIGHT;
	//private TankFrame tankFrame;
	private int x, y;
	private Group group;
	private int step = 0;
	
	public Explode(int x, int y ,TankFrame tankFrame,Group group) {
		this.x = x;
		this.y = y;
		//this.tankFrame = tankFrame;
		this.group = group;
		if (group == Group.GOOD){
			WIDTH = ResourceMgr.goodExplodes[0].getWidth();
			HEIGHT = ResourceMgr.goodExplodes[0].getHeight();
		}else if (group == Group.BAD){
			WIDTH = ResourceMgr.badExplodes[0].getWidth();
			HEIGHT = ResourceMgr.badExplodes[0].getHeight();
		}
		/*播放爆炸音效*/
		new Thread(()->new Audio("audio/explode.wav").play()).start();
	}
	
	

	public void paint(Graphics g) {
		if (this.group == Group.GOOD){
			g.drawImage(ResourceMgr.goodExplodes[step++], x, y, null);
			if(step >= ResourceMgr.goodExplodes.length)
				TankFrame.getInstance().explodes.remove(this);
		}else {
			g.drawImage(ResourceMgr.badExplodes[step++], x, y, null);
			if(step >= ResourceMgr.goodExplodes.length)
				TankFrame.getInstance().explodes.remove(this);
		}
	}
	
	

}
